package cn.lazyturtle.bugpush.schedule;

import cn.lazyturtle.bugpush.service.PushBugService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;


/**
 * <p>
 * Schedule :
 * </p>
 *
 * @author cwh
 * @since 2021-10-21
 */
@Component
@Slf4j
public class Schedule {
    private final PushBugService pushBugService;

    @Autowired
    public Schedule(PushBugService pushBugService) {
        this.pushBugService = pushBugService;
    }

    @Scheduled(cron = "0/30 * * * * ?")
    public void pushBug(){
        log.info("开始推送bug");
        try {
            pushBugService.getLastDynamicBug();
        } catch (Exception e) {
            log.info("getLastDynamicBug定时任务异常:{}",e.getMessage());
        }
        log.info("结束推送bug");
    }

    @Scheduled(cron = "0 0 0 1/1 * ? ")
    public void pushUsers(){
        log.info("开始推送users");
        try {
            pushBugService.getNameMap();
        } catch (Exception e) {
            log.info("getNameMap定时任务异常:{}",e.getMessage());
        }
        log.info("结束推送users");
    }
}
